/**
 * @file inboundTags.ts
 * @description Inbound 线索标签预设与强度分级（主色基于 success，随强度递进加深）
 */

export type InboundTagStrength = 'weak' | 'medium' | 'strong' | 'high'

export type InboundTagKey =
  | 'replied'
  | 'friended'
  | 'liked'
  | 'viewed'
  | 'shared'
  | 'rfq'
  | 'rfp'
  | 'qtt'
  | 'tech_talk'
  | 'tac_support'
  | 'f2f_meeting'
  | 'recommended'

export interface InboundTagPreset {
  key: InboundTagKey
  aliases?: string[]
  label: { en: string; zh: string }
  description: { en: string; zh: string }
  strength: InboundTagStrength
  /** 1(弱)→4(高) */
  level: 1 | 2 | 3 | 4
  /**
   * 可选：旧版固定色数据（已弃用，保留兼容）
   */
  color?: {
    theme: 'success'
    bg: string
    fg: string
    border?: string
  }
}

/**
 * 使用 success 主色 + 单一透明度 alpha 控制强弱（不再区分 bg 和 border）
 * - 使用 Vuetify CSS 变量：--v-theme-success
 * - 背景：rgba(var(--v-theme-success), alpha)
 * - 边框：rgba(var(--v-theme-success), alpha)
 * - 文本：统一使用绿色文本 rgb(var(--v-theme-success))
 */
export const INBOUND_STRENGTH_OPACITY: Record<InboundTagStrength, number> = {
  weak: 0.2,
  medium: 0.35,
  strong: 0.6,
  high: 1
}

export const INBOUND_TAG_PRESETS: InboundTagPreset[] = [
  {
    key: 'viewed',
    aliases: ['read', 'opened'],
    label: { en: 'Viewed', zh: 'Viewed' },
    description: {
      en: 'Customer viewed content (email read, page visited, download, etc.).',
      zh: '客户 查看了我们发送的内容（如邮件已读、访问页面、下载资料等），但没有进一步互动。'
    },
    strength: 'weak',
    level: 1
  },
  {
    key: 'liked',
    aliases: ['thumbs_up'],
    label: { en: 'Liked', zh: 'Liked' },
    description: {
      en: 'Customer liked our content or social posts (e.g., LinkedIn like).',
      zh: '客户 点赞 了我们的内容或社媒动态（例如在 LinkedIn 点赞）——轻度互动。'
    },
    strength: 'weak',
    level: 1
  },
  {
    key: 'shared',
    aliases: ['reposted'],
    label: { en: 'Shared', zh: 'Shared' },
    description: {
      en: 'Customer shared/forwarded our content, indicating higher recognition.',
      zh: '客户 转发/分享 了我们的内容。说明可能对内容认可度较高。'
    },
    strength: 'weak',
    level: 1
  },
  {
    key: 'friended',
    aliases: ['connected', 'added_friend'],
    label: { en: 'Friended', zh: 'Friended' },
    description: {
      en: 'Customer added/connected with us (WeChat / WhatsApp / LinkedIn).',
      zh: '客户 添加了我们为好友（例如微信 / WhatsApp / LinkedIn 连接成功）。'
    },
    strength: 'medium',
    level: 2
  },
  {
    key: 'replied',
    aliases: ['responded'],
    label: { en: 'Replied', zh: 'Replied' },
    description: {
      en: 'Customer replied to our email/message, indicating interest or intent.',
      zh: '客户对我们发出的邮件/消息 有回复。说明有一定兴趣或沟通意向。'
    },
    strength: 'medium',
    level: 2
  },
  {
    key: 'tech_talk',
    aliases: ['technical_discussion'],
    label: { en: 'Tech Talk', zh: 'Tech Talk' },
    description: {
      en: 'Technical-level discussion (solution/feasibility), typically deeper intent.',
      zh: '与客户进行了 技术层面讨论，例如产品方案、技术可行性沟通等。通常意向较深入。'
    },
    strength: 'medium',
    level: 2
  },
  {
    key: 'rfq',
    aliases: ['request_for_quotation'],
    label: { en: 'Request for Quotation', zh: 'RFQ' },
    description: { en: 'Request for Quotation.', zh: '报价请求' },
    strength: 'strong',
    level: 3
  },
  {
    key: 'rfp',
    aliases: ['request_for_proposal'],
    label: { en: 'Request for Proposal', zh: 'RFP' },
    description: { en: 'Request for Proposal / Tender.', zh: '招标/方案请求' },
    strength: 'strong',
    level: 3
  },
  {
    key: 'qtt',
    aliases: ['quote_to_trade', 'quote_to_close'],
    label: { en: 'Quote-to-Trade', zh: 'QTT' },
    description: { en: 'Quote to trade/close process.', zh: '报价 → 成交流程' },
    strength: 'strong',
    level: 3
  },
  {
    key: 'tac_support',
    aliases: ['support', 'ticket'],
    label: { en: 'TAC Support', zh: 'TAC Support' },
    description: {
      en: 'Technical assistance request; indicates use-case or trial phase.',
      zh: '技术支持（Technical Assistance Center）请求，即客户遇到问题需要帮助，表示已有使用场景或试用阶段。'
    },
    strength: 'strong',
    level: 3
  },
  {
    key: 'f2f_meeting',
    aliases: ['face_to_face_meeting', 'in_person_meeting'],
    label: { en: 'Face-to-Face Meeting', zh: 'F2F Meeting' },
    description: {
      en: 'Face-to-face meeting; indicates deeper negotiation or intent.',
      zh: '面对面会议（Face-to-Face Meeting），说明双方已具有较深合作或洽谈意愿。'
    },
    strength: 'high',
    level: 4
  },
  {
    key: 'recommended',
    aliases: ['referred'],
    label: { en: 'Recommended', zh: 'Recommended' },
    description: {
      en: 'Customer is recommended by a third party or internal reference.',
      zh: '客户是由 第三方推荐 或内部人员推荐而来，属于较可信优质线索。'
    },
    strength: 'high',
    level: 4
  }
]

export const INBOUND_TAG_BY_KEY: Record<InboundTagKey, InboundTagPreset> =
  INBOUND_TAG_PRESETS.reduce(
    (map, p) => {
      map[p.key] = p
      return map
    },
    {} as Record<InboundTagKey, InboundTagPreset>
  )

export function getInboundTagPreset(key: InboundTagKey): InboundTagPreset | undefined {
  return INBOUND_TAG_BY_KEY[key]
}

/**
 * 返回用于渲染 v-chip / v-badge 的简单样式（可选）
 * 注：若你希望完全走主题色，可忽略 bg/fg，直接用 color='success' + variant/tonal
 */
export function getInboundTagChipStyle(
  key: InboundTagKey
): { style: Record<string, string> } | undefined {
  const p = INBOUND_TAG_BY_KEY[key]
  if (!p) return undefined
  const alpha = INBOUND_STRENGTH_OPACITY[p.strength]
  const border = `1px solid rgba(var(--v-theme-success), ${alpha})`
  const text = ` rgba(var(--v-theme-success), ${alpha + 0.3})`
  return {
    style: {
      color: text,
      border
    }
  }
}
